package task11;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:找最近公共节点
 * User: 东莞呵呵
 * Date:2022-09-22
 * Time:21:42
 */
public class Demo1 {
    public int getLCA(int a, int b) {
        // write code here
        HashSet<Integer> set=new HashSet<>();
        while(a>0){
            set.add(a);
            a/=2;
        }
        while (b>0){
            if (set.contains(b)){
                return b;
            }else{
                b=b/2;
            }
        }
        return 0;
    }
}
